package com.homework.controller;

import com.homework.pojo.Employee;
import com.homework.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/findAll")
    public String findAll(Model model) {
        List<Employee> employees = employeeService.findAll();
        model.addAttribute("employees", employees);
        return "list";
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(Employee employee) {
        System.out.println(employee);
        employeeService.save(employee);
        return "redirect:/emp/findAll";
    }
}
